import { API_OPERATOR_URL } from '@/config/api';
import { AnyObject, HttpResponse, PageResponse } from '@/types/global';
import { OperatorInviteItem, OperatorItem } from '@/types/operators';
import axios from 'axios';
import { CourseItem } from '@/types/course';

export function getInviteList(data: AnyObject) {
  return axios.post<HttpResponse<PageResponse<OperatorInviteItem>>>(
    `${API_OPERATOR_URL}/invite/page`,
    data
  );
}

export function createInvite(data: AnyObject) {
  return axios.post<HttpResponse<OperatorInviteItem>>(
    `${API_OPERATOR_URL}/invite`,
    data
  );
}

export function deleteInvite(id: string) {
  return axios.delete<HttpResponse>(`${API_OPERATOR_URL}/invite/${id}`);
}

export function refuseInvite(id: string, data: AnyObject) {
  return axios.post<HttpResponse>(
    `${API_OPERATOR_URL}/invite/refuse/${id}`,
    data
  );
}

export function passInvite(id: string) {
  return axios.post<HttpResponse>(`${API_OPERATOR_URL}/invite/pass/${id}`);
}

export function getInviteDetail(id: string) {
  return axios.get<HttpResponse<OperatorInviteItem>>(
    `${API_OPERATOR_URL}/invite/${id}`
  );
}

export function getOperatorList(data: AnyObject) {
  return axios.post<HttpResponse<PageResponse<OperatorItem>>>(
    `${API_OPERATOR_URL}/page`,
    data
  );
}

export function getOperatorDetail(id: string) {
  return axios.get<HttpResponse<OperatorItem>>(`/api/v1/operator/${id}`);
}

export function getOperatorCourses(operatorId: string) {
  return axios.get<HttpResponse<CourseItem[]>>(
    `/api/v1/admin/operator/course?operatorId=${operatorId}`
  );
}

export function addOperatorCourse(operatorId: string, courseId: string) {
  return axios.post(
    `/api/v1/admin/operator/course?operatorId=${operatorId}&courseId=${courseId}`
  );
}

export function deleteOperatorCourse(operatorId: string, courseId: string) {
  return axios.delete(
    `/api/v1/admin/operator/course?operatorId=${operatorId}&courseId=${courseId}`
  );
}
